package com.cspg.design.ui.project;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;

import androidx.appcompat.app.AppCompatActivity;

import com.cspg.design.R;
import com.cspg.design.dto.ProjectInformation;
import com.cspg.design.presenter.ProjectPresenter;
import com.cspg.design.utils.ActionBarUtil;
import com.cspg.design.utils.AppManager;
import com.cspg.design.utils.StatusBarUtil;
import com.cspg.design.widget.ToastUtils;

public class ProjectInfoActivity extends AppCompatActivity {

    private ProjectPresenter projectPresenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_project_info);
        AppManager.getAppManager().addActivity(this);
        StatusBarUtil.setStatusBarColor(this, R.color.colorPrimary);
        ActionBarUtil.setActionBar(this, R.string.project_info);
        Intent intent = getIntent();
        String projectId = intent.getStringExtra("projectId");
        if (projectId == null)
        {
            ToastUtils.toast(this,"项目ID获取失败");
            return;
        }

        projectPresenter = new ProjectPresenter(this);
        projectPresenter.getProjectInformation(projectId);
    }



    /**
     * 点击空白区域隐藏键盘.
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (ProjectInfoActivity.this.getCurrentFocus() != null) {
                if (ProjectInfoActivity.this.getCurrentFocus().getWindowToken() != null) {
                    imm.hideSoftInputFromWindow(ProjectInfoActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                }
            }
        }
        return super.onTouchEvent(event);
    }
}